import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * JUnit test class to test the getBooleanElementValue in Profile.java after refactoring for message chain smell
 * @author JIAQI
 *
 */
public class TestGetBooleanFromElement {

	@Test
	public void test() {
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

		DocumentBuilder builder;
		try {
			builder = factory.newDocumentBuilder();

			Document document = builder.newDocument();
			// Create from whole cloth
			Element element = (Element) document.createElement("rootElement");
			element.setAttribute("trueAttribute", "true");

			boolean boolValue1 = Boolean.valueOf(element.getAttribute("trueAttribute")).booleanValue();
			assertTrue(boolValue1);
			boolean boolValue2 = Profile.getBooleanElementValue(element, "trueAttribute");
			assertTrue(boolValue2);

			Element element2 = (Element) document.createElement("rootElement");
			element.setAttribute("falseAttribute", "false");

			boolValue1 = Boolean.valueOf(element.getAttribute("falseAttribute")).booleanValue();
			assertFalse(boolValue1);
			boolValue2 = Profile.getBooleanElementValue(element, "falseAttribute");
			assertFalse(boolValue2);
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
